<template>
    <div class="wrap normal">
        <!-- 搜索条件 -->
        <div class="wrap-form" id="wrap-form">
            <div class="left-panel">
                <el-form :inline="true" :model="form" label-width="110px" @submit.native.prevent>
                    <el-form-item label="下单用户手机号">
                        <el-input v-model="form.mobile" placeholder="请输入" clearable style="width: 220px"></el-input>
                    </el-form-item>
                    <el-form-item label="快递单号">
                        <el-input v-model="form.courierNumber" placeholder="请输入" clearable style="width: 220px"></el-input>
                    </el-form-item>
                    <el-form-item label="工单处理单号">
                        <el-input v-model="form.complaintNumber" placeholder="请输入" clearable style="width: 220px"></el-input>
                    </el-form-item>
                    <el-form-item label="工单类型编码">
                        <el-select v-model="form.ticketTypeCode" placeholder="请选择" clearable style="width: 220px">
                            <el-option v-for="(item, index) in workOrderTypeOptions" :key="index" :label="item.ticketTypeName" :value="item.ticketTypeCode"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="工单处理状态">
                        <el-select v-model="form.workOrderStatus" placeholder="请选择" clearable style="width: 220px">
                            <el-option v-for="(item, index) in workOrderStatusOptions" :key="index" :label="item.label" :value="item.value"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" icon="el-icon-search" @click="pageOperate('search')">查询</el-button>
                        <el-button icon="el-icon-refresh" @click="pageOperate('refresh')">刷新</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
        <!-- table数据 -->
        <div class="wrap-table">
            <el-table :data="tableData" :max-height="tableMaxHeight" border v-loading="tableLoading" :header-cell-style="{ background: '#F5F6FA' }">
                <el-table-column type="index" label="序号" width="50" align="center"> </el-table-column>
                <el-table-column prop="courierNumber" label="快递单号" min-width="120"> </el-table-column>
                <el-table-column prop="mobile" label="下单用户手机号" min-width="120"></el-table-column>
                <el-table-column prop="ticketTypeName" label="工单类型名称" min-width="120"></el-table-column>
                <el-table-column label="工单创建时间" min-width="140">
                    <template slot-scope="scope">
                        {{ scope.row.createTime | iso8601DateTimeFormat }}
                    </template>
                </el-table-column>
                <el-table-column label="工单处理时间" min-width="140">
                    <template slot-scope="scope">
                        {{ scope.row.modifyTime | iso8601DateTimeFormat }}
                    </template>
                </el-table-column>
                <el-table-column prop="complaintNumber" label="工单处理单号" min-width="160"></el-table-column>
                <el-table-column prop="complaintContent" label="投诉内容" min-width="200"></el-table-column>
                <el-table-column label="工单提交状态" min-width="100">
                    <template slot-scope="scope">
                        {{ scope.row.submitStatus | filterWorkOrderSubmitStatus }}
                    </template>
                </el-table-column>
                <el-table-column prop="submitResultReason" label="工单提交返回结果" min-width="200"></el-table-column>
                <el-table-column label="工单状态" min-width="120">
                    <template slot-scope="scope">
                        {{ scope.row.workOrderStatus | filterWorkOrderStatus }}
                    </template>
                </el-table-column>
                <el-table-column prop="dealResult" label="处理结果" min-width="120"></el-table-column>
                <el-table-column label="数据来源" min-width="100">
                    <template slot-scope="scope">
                        {{ scope.row.source | filterWorkOrderSourceStatus }}
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="100" fixed="right">
                    <template slot-scope="scope">
                        <el-button type="text" @click="pageOperate('logistic', scope.row)">物流信息</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <pagination :total="page.totalNum" :page.sync="page.pageNum" :limit.sync="page.pageSize" layout="total, sizes, prev, pager, next, jumper" @pagination="getTableData" />
        </div>
        <!-- 弹框 -->
        <el-dialog v-if="operateDialog" :title="operateTitle" :visible.sync="operateDialog" @close="closeOperateDialog" :width="`${operateWidth}px`" :close-on-press-escape="false" :close-on-click-modal="false">
            <template v-if="operateType === 'logistic'">
                <widget-logistic ref="widgetLogistic" :id="operateForm.courierNumber"></widget-logistic>
            </template>
        </el-dialog>
    </div>
</template>

<script>
import tableHeight from '@/mixins/tableHeight'
import { getWorkOrderList, getWorkOrderTypeList } from '@/api/workOrder'
import WidgetLogistic from './components/widgetLogistic.vue'
import { workOrderStatusOptions } from '@/filters/options'
export default {
    name: 'WorkOrderIndex',
    mixins: [tableHeight],
    components: {
        WidgetLogistic
    },
    data() {
        return {
            form: {
                mobile: '',
                courierNumber: '',
                ticketTypeCode: '',
                complaintNumber: '',
                workOrderStatus: ''
            },
            page: {
                pageNum: 1,
                pageSize: 10,
                totalNum: 0
            },
            tableData: [],
            tableLoading: false,
            // 类型
            operateType: '',
            // 标题
            operateTitle: '',
            // 弹框
            operateDialog: false,
            // 宽度
            operateWidth: 550,
            // loading
            operateLoading: false,
            // 操作form
            operateForm: {
                courierNumber: ''
            },
            operateRules: {

            },
            // 工单处理状态
            workOrderStatusOptions,
            // 工单类型
            workOrderTypeOptions: []
        };
    },
    methods: {
        // 初始化工单选项
        initWorkOrderType() {
            getWorkOrderTypeList().then(res => {
                this.workOrderTypeOptions = res.data
            }).catch(error => {})
        },
        // 数据
        getTableData() {
            this.tableLoading = true
            const data = {
                pageNum: this.page.pageNum,
                pageSize: this.page.pageSize,
                ...this.form
            }
            getWorkOrderList(data).then(res => {
                this.tableLoading = false
                this.tableData = res.data.records
                this.page.totalNum = res.data.total
            }).catch(error => {
                this.tableLoading = false
            })
        },
        // 操作
        pageOperate(type, row) {
            this.operateType = type
            switch (type) {
                case 'search':
                    this.getTableData()
                    break;
                case 'refresh':
                    Object.assign(this.$data, this.$options.data())
                    this.getTableData()
                    break;
                case 'logistic':
                    this.operateTitle = '物流信息'
                    this.operateWidth = 800
                    this.operateDialog = true
                    this.operateForm.courierNumber = row.courierNumber
                    this.$nextTick(() => {
                        this.$refs.widgetLogistic.initLogistic()
                    })
                    break;
                default:
                    break;
            }
        },
        // 关闭操作按钮
        closeOperateDialog() {
            this.operateLoading = false
            this.operateDialog = false
            this.operateTitle = ''
            this.operateType = ''
            this.operateForm = this.$options.data().operateForm
        }
    },
    mounted() {
        this.getTableData()
        this.initWorkOrderType()
    }
};
</script>

<style lang="scss" scoped>
</style>